package com.dragon.mmochat.model.scheduleJob;

import java.awt.Color;

import org.quartz.Job;
import org.quartz.JobExecutionContext;

import com.dragon.mmochat.model.activity.MmochatFirstPayAwardInfo;
import com.dragon.mmochat.model.activity.MmochatSystemState;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.dragon.mmochat.service.MmochatChatService;
import com.dragon.mmochat.service.MmochatFriendService;
import com.dragon.mmochat.service.MmochatMainService;
import com.dragon.mmochat.service.MmochatPropService;
import com.dragon.mmochat.util.MmochatUtil;

public class FirstPayAwardJob implements Job {
	@Override
	public void execute(JobExecutionContext context) {
		try {
			MmochatFirstPayAwardInfo payAward = (MmochatFirstPayAwardInfo) context
					.getJobDetail().getJobDataMap().get("data");
			if (payAward != null) {
				MmochatSystemState.setFirstPay_open(payAward.isFirstPay_open());
				MmochatSystemState.setFirstPay_minLevel(payAward
						.getFirstPay_minLevel());
				MmochatSystemState.setFirstPay_daoAward(payAward
						.getFirstPay_daoAward());
				MmochatSystemState.setFirstPay_expAward(payAward
						.getFirstPay_expAward());
				MmochatSystemState.setFirstPay_timeInfo(payAward
						.getFirstPay_timeInfo());
				if (payAward.isFirstPay_open()) {
					String info = MmochatUtil.wrapColor("首次充值送豪礼",
							Color.magenta)
							+ "活动开始啦!您只要在"
							+ payAward.getFirstPay_timeInfo()
							+ "期间，按9键充值元宝，进行K币兑换或充值卡充值，即可获得"
							+ MmochatUtil.wrapColor(payAward
									.getFirstPay_daoAward()
									+ "年道行、"
									+ payAward.getFirstPay_expAward()
									+ "次打怪经验", Color.red) + "!一生只有一次的机会!";
					info = MmochatUtil.wrapColor(info, Color.yellow);
					for (MmochatPlayer me : MmochatMainService.players.values()) {
						if (MmochatPropService.canTakeFirstPayAward(me)) {
							MmochatFriendService
									.sendMsgToPersonByFriendMessage(me, info);
							MmochatChatService.sendSystemMsgToPerson(me, info);
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
